#include <stdio.h>
#include <math.h>

void rotate(int matrix[4][4]) {
    int new_matrix[4][4];
    
    new_matrix[0][0] = matrix[3][0];
    new_matrix[0][1] = matrix[2][0];
    new_matrix[0][2] = matrix[1][0];
    new_matrix[0][3] = matrix[0][0];
    new_matrix[1][0] = matrix[3][1];
    new_matrix[1][1] = matrix[1][1];
    new_matrix[1][2] = matrix[1][2];
    new_matrix[1][3] = matrix[0][1];
    new_matrix[2][0] = matrix[3][2];
    new_matrix[2][1] = matrix[2][1];
    new_matrix[2][2] = matrix[2][2];
    new_matrix[2][3] = matrix[0][2];
    new_matrix[3][0] = matrix[3][3];
    new_matrix[3][1] = matrix[2][3];
    new_matrix[3][2] = matrix[1][3];
    new_matrix[3][3] = matrix[0][3];
    
    for (int y = 0; y < 4; y++) {
        for (int x = 0; x < 4; x++) {
            matrix[y][x] = new_matrix[y][x];
        }
    }
}

int calc_sum(int matrix[4][4], int x, int y) {
    return matrix[y][x] + matrix[y + 1][x]
            + matrix[y][x + 1] + matrix[y + 1][x + 1];
}

int max_sum(int matrix[4][4]) {
    int max = 0;
    for (int y = 0; y < 3; y++) {
        for(int x = 0; x < 3; x++) {
            int sum = calc_sum(matrix, y, x);
            if (max < sum) {
                max = sum;
            }
        }
    }
    return max;
}

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int matrix[4][4];
        for (int y = 0; y < 4; y++) {
            for (int x = 0; x < 4; x++) {
                scanf(" %d", &matrix[y][x]);
            }
        }
        int j = 0;
        int max = 0;
        do {
            int matrix_max = max_sum(matrix);
            if (matrix_max > max) {
                max = matrix_max;
            }
            rotate(matrix);
        } while(j++ < 4);
        printf("%d\n", max);
    }
    return 0;
}
